﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Demo.Classroom
{
    public partial class DemoComplexBinding : Form
    {
        BindingList<HocVien> hocVienList = new BindingList<HocVien>();
        public DemoComplexBinding()
        {
            InitializeComponent();

            hocVienList.Add(new HocVien("Mr A", 1));
            hocVienList.Add(new HocVien("Mr B", 2));
            hocVienList.Add(new HocVien("Mr C", 3));
            hocVienList.Add(new HocVien("Mr D", 4));

            comboBox1.DisplayMember = "Name";
            comboBox1.DataSource = hocVienList;
            dataGridView1.DataSource = hocVienList;

            label2.DataBindings.Add("Text", hocVienList, "Name");
            textBox1.DataBindings.Add("Text", hocVienList, "Score");
        }

        private void showButton_Click(object sender, EventArgs e)
        {
            label1.Text = hocVienList[0].Name + " - " + hocVienList[0].Score;
        }

        private void changeButton_Click(object sender, EventArgs e)
        {
            hocVienList[hocVienList.Count - 1].Name += " Updated";
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            hocVienList.Add(new HocVien("Mr Last", 0));
        }
    }
}
